<template>
	<view class="conact-content">
		<!-- 这里设置了z-paging加载时禁止自动调用reload方法，自行控制何时reload（懒加载）-->
		<!--  :enable-back-to-top="currentIndex===tabIndex" 在微信小程序上可以多加这一句，因为默认是允许点击返回顶部的，但是这个页面有多个scroll-view，会全部返回顶部，所以需要控制是当前index才允许点击返回顶部 -->
		<z-paging ref="paging" v-model="dataList" @query="queryList" :fixed="false" :auto="true">
			<view class="" slot="top" style="background-color: #F8F8F8;">
				<u-navbar class="navbar" :border-bottom="false" title="消息" :title-size="36" :title-bold="true" :title-color="textColor">
				</u-navbar>
			</view>
			<!-- 如果希望其他view跟着页面滚动，可以放在z-paging标签内 -->
			<view class="u-p-l-35 u-p-r-35 u-p-t-35">
				<view class="item" v-for="(item, index) in dataList" :key="index"  @click="toPage(item.messageType,item.unReadCount,index)" >
					<image src="/static/xiaoxi/dingdan.png" class="message-image" style="" mode="" v-if="item.messageType === 0"></image>
					<image src="/static/xiaoxi/xitongxiaoxi.png"  class="message-image" mode="" v-if="item.messageType === 1"></image>
					<image src="/static/xiaoxi/chaoshitixing.png" class="message-image" mode="" v-if="item.messageType === 2"></image>
					<view class="u-m-l-20">
						<view class="u-font-30">{{item.fromShopName}}</view>
						<view class="u-font-24 grey-color">
							{{ item.contentExcerpt }}
						</view>
					</view>
					<view class="u-font-24 grey-color" style="position: absolute;right: 0;top:0;">
						<view class="">
							{{ disabledDate(item.lastSendTime )}}
						</view>
						<view class="u-flex u-row-right" v-if="item.unReadCount">
							<text class="message-badge">{{item.unReadCount}}</text>
							<!-- <u-badge v-if="item.unReadCount" :count="item.unReadCount" :offset="[-8, -8]" :bgColor="badgeColor" size="mini"></u-badge> -->
						</view>
					</view>
				</view>
			</view>
			
			
		</z-paging>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList: []
			}
		},
		onLoad() {
		},
		// onShow() {
		// 	this.$refs.paging.reload();
		// },
		methods: {
			async queryList(pageNo, pageSize) {
				//组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//模拟请求服务器获取分页数据，请替换成自己的网络请求
				const params = {
					pageIndex: pageNo,
					pageSize: pageSize,
				};
				uni.showLoading({
					title: 'loading...',
					mask: false
				});
				const res = await this.$newHttp.get('api/Message/GetContactList', { params: params } );
				uni.hideLoading({
					title: 'loading...'
				});
				if(res.code === 200){
					this.$refs.paging.complete(res.data.list);
				}else{
					this.$refs.paging.complete(false);
				}
			},
			// 时间格式化 前一天和当前时间
			disabledDate(time) {
				var date = new Date(time).getDate();
				var now = new Date().getDate();
				if (date < now) {
					return this.$fui.dateFormatter(time);
				} else {
					return this.$fui.dateFormatter(time,'hh:MM');
				}
			},
			async toPage(type,count,index) {
				// 更新未读消息数量
				if(count!==0){
					// await this.$store.dispatch('shop/getMessageNum');
					// let newCount = this.$store.state.shop.setMsgBadge - count;
					// this.$store.commit('shop/SET_MSG_BADGE',newCount);
					this.dataList[index].unReadCount = 0;
				}
				this.$mRouter.push({ route: '/pages/public/xiaoxi/messageDeatails?type='+type });
				// if (type == 1 || type == 2) {
				// 	this.$mRouter.push({ route: '/pages/public/kefu' });
				// }
			}
		}
	}
</script>

<style>
	page {
		background-color: #FFFFFF;
	}
</style>

<style lang="scss" scoped>
	.conact-content{
		height: 100%;
		.message-badge{
			display: inline-block;
			background-color: #FF551A;
			color:#fff;
			font-size: 24rpx;
			box-sizing: border-box;
			padding: 4rpx 22rpx;
			text-align: right;
			border-radius: 18rpx;
			margin-top: 10rpx;
		}
	}
	.item {
		border-bottom: 2rpx solid #F3F3F3;
		position: relative;
		display: flex;
		align-items: center;
		margin-bottom: 30rpx;
		padding-bottom: 30rpx;
	}
	.message-image{
		width: 88rpx;height:88rpx;
		box-shadow: 0px 0px 18px 2px rgba(8,1,3,0.1);
		border-radius: 50%;
	}
</style>
